/**
 * Copyright 2011 Mathieu Magnaudet
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package edu.enac.geoapp.parser.pln;


/**
 * Builder for {@link MapPoint} 
 * @author mathieu
 *
 */
public class MapPointBuilder {
	/**
	 * Static method that builds a {@link MapPoint} from two {@link Coordinates}
	 * @param id the id to set
	 * @param latitude latitude coordinate
	 * @param longitude longitude coordinate
	 * @return the builded MapPoint
	 */
	public static MapPoint buildMapPoint(String id, Coordinate latitude, Coordinate longitude) {
		return  new MapPoint(id, getDegre(latitude.getDeg()), Integer.parseInt(latitude.getMin()),
				getSeconds(latitude.getHundredthMin()), getDegre(longitude.getDeg()), Integer.parseInt(longitude
						.getMin()), getSeconds(longitude.getHundredthMin()), getOrientation(longitude.getDeg()) );
	}
	
	private static int getDegre(String lg) {
		return Integer.parseInt(lg.substring(1));
	}

	private static boolean getOrientation(String in) {
		return (!in.startsWith("E"));
	}

	private static int getSeconds(String hundMin) {
		return (int) (0.6f * Integer.parseInt(hundMin));
	}
}
